def wels(z):
    h = z
    for j in range(2, z-1, 1):
        if (z / j == int(z/j)):
            h=j 
    if h == z:
        return 1 
    else:
        return 0
        
f = int(input(""))

if (f >= 1000 and f <=9999 and f == int(f)):
    rdsv = 0 
    if wels (f):
        rdsv = f
    else:
        m1 = int(f/1000)
        m2 = int(f/100-m1*10)
        m3 = int(f/10-m1*100-m2*10)
        m4 = int(f-m1*1000-m2*100-m3*10)
        
        if wels(m1*10+m2)>rdsv:
            rdsv = m1*10+m2
            
        if wels(m2*10+m3)>rdsv:
            rdsv = m2*10+m3
            
        if wels(m3*10+m4)>rdsv:
            rdsv = m3*10+m4
            
        if wels(m1*100+m2*10+m3)>rdsv:
            rdsv = m1*100+m2*10+m3
            
        if wels(m2*100+m3*10+m4)>rdsv:
            rdsv = m2*100+m3*10+m4
            
    print(rdsv)
else:
    print(0)
        
        
        


    
    
    
   
         
         
     
        
    
    
    
    
    
    
    
    
    
        
        
        
        
        
        
        
        
        
        
        
        
         
